<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" placeholder="请输入用户名" id="user">
    <script>
        var user = document.getElementById("user")
        user.onkeyup = function(event){
            if(event.keyCode == 13){
                var value = this.value.trim()
                var reg =/^[A-z]{1,8}$/
                console.log(reg.test(value));
            }
        }
    </script>
</body>
</html>